﻿using System.IO;
using System.IO.Compression;

namespace XiaoSe.IO.Compression
{
    public class GZipStreamEx
    {
        public static byte[] GZipDecompress(byte[] source)
        {
            MemoryStream streamZip = new MemoryStream(source);
            streamZip.Seek(0, SeekOrigin.Begin);
            GZipStream gZipStream = new GZipStream(streamZip, CompressionMode.Decompress, false);
            MemoryStream streamDe = new MemoryStream();
            int lenght;
            byte[] bTemp = new byte[1024];
            do
            {
                lenght = gZipStream.Read(bTemp, 0, bTemp.Length);
                streamDe.Write(bTemp, 0, lenght);
            }
            while (lenght >= 1024);
            byte[] data = streamDe.ToArray();
            streamDe.Close();
            gZipStream.Close();
            streamZip.Close();
            return data;
        }
    }
}
